/* Copyright 2012 Ilkka Kiistala

This file is part of the Crossmodal-Framework. The Crossmodal-Framework is free software: you can redistribute it and/or modify it under the terms of the GNU 
General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The Crossmodal-Framework is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along 
with the Crossmodal Framework.  If not, see <http://www.gnu.org/licenses/> */

package com.example.jsontotactons;

import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class TactonList extends ListActivity {

	private Experiment exp;
    private View textEntryView = null;
    private ArrayAdapter<String> tactonListAdapter = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.teams);
        registerForContextMenu(getListView());
    }

    @Override
    protected void onResume() {
        super.onResume();
        tactonListAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Experiment.tactonNames(this));
        setListAdapter(tactonListAdapter);
        getListView().setTextFilterEnabled(true);
        // getTextEntryView();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        // MenuInflater inflater = getMenuInflater();
        //inflater.inflate(R.menu.teams_options_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        /*
            Logger.d("Displaying the add team dialog box");
            displayAddTeamDialog();
            return true;
         */
        default:
            Logger.e("Unknown menu item selected");
            return false;
        }
    }

//    @Override
//    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
//        super.onCreateContextMenu(menu, v, menuInfo);
//        MenuInflater inflater = getMenuInflater();
//        inflater.inflate(R.menu.teams_context_menu, menu);
//    }
//
//    public boolean onContextItemSelected(MenuItem item) {
//        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
//        switch (item.getItemId()) {
//        case R.id.delete_team:
//            positionOfTeamToDelete = info.position;
//            showDialog(CONFIRM_DELETE_DIALOG);
//            return true;
//        default:
//            return super.onContextItemSelected(item);
//        }
//    }

    @Override
    protected void onListItemClick(ListView listView, View view, int position, long id) {
        String teamName = tactonListAdapter.getItem(position);

        // TODO:
        //Intent intent = new Intent(this, TeamDetails.class);
        //intent.putExtra("teamName", teamName);
        //startActivity(intent);
    }


//    @Override
//    protected void onPrepareDialog(int id, Dialog dialog) {
//        EditText collectedTextView = (EditText) getTextEntryView().findViewById(R.id.collected_text);
//        collectedTextView.setText("");
//    }

//    synchronized protected View getTextEntryView() {
//        if (textEntryView == null) {
//            LayoutInflater factory = LayoutInflater.from(this);
//            textEntryView = factory.inflate(R.layout.collect_text, null);
//        }
//        return textEntryView;
//    }

//    protected DialogInterface.OnClickListener addTeamButtonListener() {
//        return new DialogInterface.OnClickListener() {
//            public void onClick(DialogInterface dialog, int id) {
//                EditText collectedTextView = (EditText) getTextEntryView().findViewById(R.id.collected_text);
//                String name = collectedTextView.getText().toString();
//                Team.create(name, TactonList.this);
//                tactonListAdapter.add(name);
//            }
//        };
//    }

//    protected DialogInterface.OnClickListener deleteTeamConfirmationListener() {
//        return new DialogInterface.OnClickListener() {
//            public void onClick(DialogInterface dialog, int id) {
//                String teamName = tactonListAdapter.getItem(positionOfTeamToDelete);
//                deleteTeam(teamName);
//                tactonListAdapter.remove(teamName);
//            }
//        };
//    }

    protected DialogInterface.OnClickListener cancelListener() {
        return new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        };
    }

//    public AlertDialog getCreateTeamDialog() {
//        return (AlertDialog) createTeamDialog;
//    }
//
//    public AlertDialog getConfirmDeleteTeamDialog() {
//        return (AlertDialog) confirmDeleteTeamDialog;
//    }
}
